home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / exec / compare.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-08  |  2.2 KB  |  77 lines

  1. /*
  2. \funcref{compare}{void compare (\params)}
  3.     {
  4.         {VAR\_} {lval} {left variable to compare}
  5.         {VAR\_} {rval} {right variable to compare}
  6.     }
  7.     {}
  8.     {}
  9.     {}
  10.     {compare.c}
  11.     {
  12.  
  13.         This function compares two {\em VAR\_} type variables and pushes the
  14.         result of the comparison. Comparisons between different types (e.g.,
  15.         between a string and a list) should never occur, since the compiler
  16.         either generates opcodes for type casting or issues an error.
  17.  
  18.         The comparison between non-list types is either an integer subtraction,
  19.         or a {\em strcmp()}. The comparison between two lists is performed as
  20.         follows:
  21.  
  22.         \begin{itemize}
  23.  
  24.             \item If the lists do not have the same size, then the list with
  25.             the bigger size is larger.
  26.  
  27.             \item For all elements in the list, a string comparison is made.
  28.             made. If this comparison indicates non-zero, the list with the
  29.             alphabetically higher string is larger.
  30.  
  31.         \end{itemize}
  32.  
  33.         The return value of {\em compare()} is a {\em VAR\_} struct with type
  34.         {\em e\_int}. The {\em vu.intval} field is the result of comparison,
  35.         with the value $<0$ meaning that {\em rval} is larger; $>0$ meaning
  36.         that {\em lval} is larger, or $0$ meaning that {\em lval == rval}.
  37. }
  38.  
  39. */
  40.  
  41. #include "icm-exec.h"
  42.  
  43. void compare (lval, rval)
  44. VAR_ lval, rval;
  45. {
  46.     register unsigned
  47.         i;
  48.     register LIST_
  49.         *llist,
  50.         *rlist;
  51.     VAR_
  52.         ret;
  53.  
  54.     ret.type = e_int;
  55.  
  56.     if (lval.type & e_str)
  57.         ret.vu.intval = strcmp (lval.vu.i->ls.str, rval.vu.i->ls.str);
  58.     else if (lval.type & e_int)
  59.         ret.vu.intval = lval.vu.intval - rval.vu.intval;
  60.     else
  61.     {
  62.         ret.vu.intval = 0;                  /* assume equal */
  63.         llist = &(lval.vu.i->ls.list);
  64.         rlist = &(rval.vu.i->ls.list);
  65.         if (llist->size != rlist->size)
  66.             ret.vu.intval = llist->size - rlist->size;
  67.         else
  68.             for (i = 0; i < llist->size; i++)
  69.                 if ( (ret.vu.intval = strcmp (llist->element [i],
  70.                           rlist->element [i]))
  71.                    )
  72.                     break;
  73.     }
  74.  
  75.     push (ret);
  76. }
  77.